package wiki.loader
{
	import control.FrontController;
	
	/**
	 * An instance of this class ir responsible for loading a wiki page.
	 * It consists of an HTML Element (Object) and a pageId. 
	 * A WikiPageLoader instance listens for the click event on the HTML element, 
	 * and loads the page identified by pageId.
	 */
	public class WikiPageLoader
	{
		/**
		 * Constructs a new WikiPageLoader instance
		 * @param iLinkElement - the HTML Element (an anchor element) that triggers the loading of the wiki page identified by pageId
		 * @param pageId - the id of the wiki page that must be loaded when iLinkElement is clicked by the user
		 */ 
		public function WikiPageLoader(iLinkElement:Object, pageId: String) {
			trace("new WikiPageLoader(" + iLinkElement + ", " + pageId + ")");
			
			_iLinkElement = iLinkElement;
			_pageId = pageId;
			_iLinkElement.addEventListener("click", load);
		}
		
		/**
		 * Loads the wiki page that is associated with this instance
		 */
		public function load(event: Object): void {
			trace("Load page: " + _pageId);
			_iLinkElement.removeEventListener("click", load);
			FrontController.instance.loadPage(_pageId);
		}
		
		private var _pageId: String;
		private var _iLinkElement: Object;
	}
}